package org.biz.impl;

import org.apache.log4j.Logger;
import org.biz.IBaseBiz;
import org.hibernate.dao.IBaseDao;

/**
 * 
 * 基本业务类对象实现类对象;
 * 
 * @Title: BaseBiz.java
 * @Description:新闻系统业务实现类对象
 * @Copyright: Copyright (c) 2011
 * @Company:北京学邦时代
 * @author 苗有虎
 * @date Apr 23, 2012 11:02:42 AM
 * @version V4.0
 */
@SuppressWarnings("unchecked")
public class BaseBiz implements IBaseBiz {
	protected static Logger logger = Logger.getLogger(BaseBiz.class.getName());
	private IBaseDao baseDao = null;

	public IBaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(IBaseDao baseDao) {
		this.baseDao = baseDao;
	}

	/**
	 * 添加对象
	 */
	public boolean doAddObject(Object obj) {
		boolean result = false;
		try {
			this.baseDao.saveOrUpdate(obj);
			result = true;
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return result;
	}

	/**
	 * 删除对象;
	 */
	public boolean doDelObjectById(Class clazz, int id) {
		boolean result = false;
		try {
			this.baseDao.deleteObj(this.baseDao.loadById(clazz, id));
			result = true;
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return result;
	}

	/**
	 * 批量删除对象;
	 */
	public boolean doBatchDelObjectByIds(Class entity, String clazz, String ids) {
		String sql = "delete from " + clazz + " where id in (" + ids + ")";
		return this.baseDao.delObjectBySQL(entity, sql);
	}

	/**
	 * 通过主键编号查看实体类对象;
	 */
	public Object selObjectById(Class clazz, int id) {
		return this.baseDao.loadById(clazz, id);
	}

	/**
	 * 更新对象;
	 */
	public boolean doUpdateObject(Object obj) {
		boolean result = false;
		try {
			this.baseDao.updateObject(obj);
			result = true;
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return result;
	}

	/**
	 * 通过HQL语句查询单一的对象;
	 */
	public Object selObjectByHQL(String hql) {
		return this.baseDao.loadByHql(hql);
	}
}
